package com.yutel.number;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;

public class NumberFormat {

	public static void main(String[] args) {
//		String nums="0";
//		num(nums);
//		number(nums);
//		float num=12.5254f;
//		str(num);
//		testInteger(2);
		test16bit(Integer.MAX_VALUE);
		number(0);
		
	}
	public static void number(int nums) {
		try {
			int f=~nums;
			System.out.println("nums="+nums);
			System.out.println("~nums="+f);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void number(String nums) {
		try {
			DecimalFormat df = new DecimalFormat("#.0");
			Number num=df.parse(nums);
			System.out.println("num="+num.toString());
			System.out.println("int="+num.intValue());
			System.out.println("float="+num.floatValue());
			System.out.println("double="+num.doubleValue());
			System.out.println("=============="+df.format(num));
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
	public static void num(String nums) {
		BigDecimal score = new BigDecimal(nums);
    	double score_value = score.setScale(1,BigDecimal.ROUND_HALF_DOWN).doubleValue();
    	System.out.println("score_value=============="+score_value);
	}
	public static void str(float num) {
		try {
			DecimalFormat df = new DecimalFormat("#.00");
			System.out.println("#.00="+df.format(num));
			System.out.println("#="+new DecimalFormat("#").format(num));
			
			System.out.println("rand="+Math.round(num));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void testInteger(int num) {
		try {
			System.out.println("num=" + num);
			int out1 = ~num;
			System.out.println("~num=" + out1);
			int out2 = 0 & num;
			System.out.println("0 & num=" + out2);
			int out3 = 1 & num;
			System.out.println("6 & num=" + out3);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void test16bit(int num) {
		try {
			System.out.println("num=" + num);
			int out1 = num & 0xff;
			System.out.println("num&0xff=" + out1);
			int out2 = num & 0xffff;
			System.out.println("num&0xffff=" + out2);
			int out3 = num & 0xffffff;
			System.out.println("num&0xffffff=" + out3);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
